package com.shujia.sql

import com.shujia.core.ScoreObj
import org.apache.spark.SparkContext
import org.apache.spark.rdd.RDD
import org.apache.spark.sql.{SQLContext, SparkSession}

object Code01SparkSession {
  def main(args: Array[String]): Unit = {

    //    new SparkSession()
    val spark: SparkSession = SparkSession
      .builder()
      .master("local")
      .appName("spark")
      .getOrCreate()

    val sc: SparkContext = spark.sparkContext
    val data: RDD[String] = sc.textFile("spark_code/data/score.txt")

    data
      .map {
        line => {
          val splitRes: Array[String] = line.split(",")
          ScoreObj(splitRes(0), splitRes(1), splitRes(2).toInt)
        }
      }.groupBy(_.id)
      .mapValues(_.map(x => x.score).sum)
      .foreach(println)


    val sqlContext: SQLContext = spark
      .sqlContext

//    sqlContext.

  }
}
